package com.aiju.bean;


import org.json.JSONException;
import org.json.JSONObject;


/**
 * @author: 佐为
 * @date: 2016-11-24 10:09
 * @version: V1.0
 * @Description: json数据处理
 */
public class JsonData {

    /**
     * 状态码
     */
    private int code;

    /**
     * 状态信息
     */
    private String msg;

    /**
     * 数据
     */
    private JSONObject jsonObject;

    /**
     * data数据
     */
    private Object data;

    /**
     * 额外数据
     */
    private Object ext;

    public JsonData(String json) {
        try {
            jsonObject = new JSONObject(json);
            code = jsonObject.optInt("status");
            msg = jsonObject.optString("msg");
            data = jsonObject.opt("data");
            ext = jsonObject.opt("ext");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        //600 token过期 发送全局消息
        if (code == 600) {
            //EventCenter.getInstance().post(new AppEvent());
        }
    }

    /**
     * 请求是否成功
     *
     * @return
     */
    public boolean isSuccess() {
        return code == 200;
    }

    /**
     * 支付是否成功
     *
     * @return
     */
    public boolean isPaySuccess() {
        return code == 10000;
    }

    //==================get set 方法区===============
    public Object getExt() {
        return ext;
    }

    public void setExt(Object ext) {
        this.ext = ext;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public JSONObject getJsonObject() {
        return jsonObject;
    }

    public void setJsonObject(JSONObject jsonObject) {
        this.jsonObject = jsonObject;
    }

}
